home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kmdichildview.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  18.6 KB  |  616 lines

  1. //----------------------------------------------------------------------------
  2. //    filename             : kmdichildview.h
  3. //----------------------------------------------------------------------------
  4. //    Project              : KDE MDI extension
  5. //
  6. //    begin                : 07/1999       by Szymon Stefanek as part of kvirc
  7. //                                         (an IRC application)
  8. //    changes              : 09/1999       by Falk Brettschneider to create an
  9. //                           - 06/2000     stand-alone Qt extension set of
  10. //                                         classes and a Qt-based library
  11. //                           2000-2003     maintained by the KDevelop project
  12. //    patches              : 02/2000       by Massimo Morin (mmorin@schedsys.com)
  13. //                           */2000        by Lars Beikirch (Lars.Beikirch@gmx.net)
  14. //                           02/2001       by Eva Brucherseifer (eva@rt.e-technik.tu-darmstadt.de)
  15. //                           01/2003       by Jens Zurheide (jens.zurheide@gmx.de)
  16. //
  17. //    copyright            : (C) 1999-2003 by Falk Brettschneider
  18. //                                         and
  19. //                                         Szymon Stefanek (stefanek@tin.it)
  20. //    email                :  falkbr@kdevelop.org (Falk Brettschneider)
  21. //----------------------------------------------------------------------------
  22. //
  23. //----------------------------------------------------------------------------
  24. //
  25. //    This program is free software; you can redistribute it and/or modify
  26. //    it under the terms of the GNU Library General Public License as
  27. //    published by the Free Software Foundation; either version 2 of the
  28. //    License, or (at your option) any later version.
  29. //
  30. //----------------------------------------------------------------------------
  31. #ifndef _KMDI_CHILD_VIEW_H_
  32. #define _KMDI_CHILD_VIEW_H_
  33.  
  34. #include <qwidget.h>
  35. #include <qpixmap.h>
  36. #include <qrect.h>
  37. #include <qapplication.h>
  38. #include <qdatetime.h>
  39.  
  40. #include "kmdichildfrm.h"
  41.  
  42. class KMdiChildViewPrivate;
  43.  
  44. /**
  45.   * @short Base class for all your special view windows.
  46.   *
  47.   * Base class for all MDI view widgets. KMdi stores additional information in this class
  48.   * to handle the attach/detach mechanism and such things.
  49.   *
  50.   * All such windows 'lives' attached to a KMdiChildFrm widget
  51.   * managed by KMdiChildArea, or detached (managed by the window manager.)
  52.   * So remember that the KMdiChildView::parent pointer may change, and may be 0L, too.
  53.   *
  54.   * There are 2 possibilities for you to put your widgets under MDI control:
  55.   *
  56.   * Either you inherit all the views from KMdiChildView:
  57.   *   \code
  58.   *   class MyMdiWidget : public KMdiChildView
  59.   *   { .... };
  60.   *   ...
  61.   *   MyMdiWidget w;
  62.   *   mainframe->addWindow(w, flags);
  63.   *   \endcode
  64.   *
  65.   * or you wrap them by a KMdiChildView somehow like this:
  66.   *
  67.   * \code
  68.   * void DocViewMan::addKMdiFrame(QWidget* pNewView, bool bShow, const QPixmap& icon)
  69.   * {
  70.   *   // cover it by a KMdi childview and add that MDI system
  71.   *   KMdiChildView* pMDICover = new KMdiChildView( pNewView->caption());
  72.   *   pMDICover->setIcon(icon);
  73.   *   m_MDICoverList.append( pMDICover);
  74.   *   QBoxLayout* pLayout = new QHBoxLayout( pMDICover, 0, -1, "layout");
  75.   *   pNewView->reparent( pMDICover, QPoint(0,0));
  76.   *   pLayout->addWidget( pNewView);
  77.   *   pMDICover->setName( pNewView->name());
  78.   *   // captions
  79.   *   QString shortName = pNewView->caption();
  80.   *   int length = shortName.length();
  81.   *   shortName = shortName.right(length - (shortName.findRev('/') +1));
  82.   *   pMDICover->setTabCaption( shortName);
  83.   *   pMDICover->setCaption(pNewView->caption());
  84.   *
  85.   *   // fake a viewActivated to update the currentEditView/currentBrowserView pointers _before_ adding to MDI control
  86.   *   slot_viewActivated( pMDICover);
  87.   *
  88.   *   // take it under MDI mainframe control (note: this triggers also a setFocus())
  89.   *   int flags;
  90.   *   if (bShow) {
  91.   *     flags = KMdi::StandardAdd;
  92.   *   }
  93.   *   else {
  94.   *     flags = KMdi::Hide;
  95.   *   }
  96.   *   // set the accelerators for Toplevel MDI mode (each toplevel window needs its own accels
  97.   *   connect( m_pParent, SIGNAL(childViewIsDetachedNow(QWidget*)), this, SLOT(initKeyAccel(QWidget*)) );
  98.   *
  99.   *   m_pParent->addWindow( pMDICover, flags);
  100.   *   // correct the default settings of KMdi ('cause we haven't a tab order for subwidget focuses)
  101.   *   pMDICover->setFirstFocusableChildWidget(0L);
  102.   *   pMDICover->setLastFocusableChildWidget(0L);
  103.   * }
  104.   * \endcode
  105.   *
  106.   */
  107.  
  108. class KMDI_EXPORT KMdiChildView : public QWidget
  109. {
  110.     friend class KMdiMainFrm;
  111.     friend class KMdiChildFrm;
  112.     Q_OBJECT
  113.  
  114.     // attributes
  115. protected:
  116.     /**
  117.      * See KMdiChildView::caption
  118.      */
  119.     QString m_szCaption;
  120.     
  121.     /**
  122.      * See KMdiChildView::tabCaption
  123.      */
  124.     QString m_sTabCaption;
  125.     
  126.     /**
  127.      * See KMdiChildView::focusedChildWidget
  128.      */
  129.     QWidget* m_focusedChildWidget;
  130.     
  131.     /**
  132.      * See KMdiChildView::setFirstFocusableChildWidget
  133.      */
  134.     QWidget* m_firstFocusableChildWidget;
  135.     
  136.     /**
  137.      * See KMdiChildView::setLastFocusableChildWidget
  138.      */
  139.     QWidget* m_lastFocusableChildWidget;
  140.     
  141.     /**
  142.      * Every child view window has an temporary ID in the Window menu of the main frame.
  143.      */
  144.     int m_windowMenuID;
  145.     
  146.     /**
  147.      * Holds a temporary information about if the MDI view state has changed but is not processed yet (pending state).
  148.      * For example it could be that a 'maximize' is pending, if this variable is true.
  149.      */
  150.     bool m_stateChanged;
  151.  
  152.     /**
  153.      * Holds the time when this view was activated (not only displayed) for the last time.
  154.      */
  155.     QDateTime m_time;
  156.  
  157. private:
  158.     /**
  159.      * Internally used as indicator whether this KMdiChildView is treated as document view or as tool view.
  160.      */
  161.     bool m_bToolView;
  162.     
  163.     /**
  164.      * Internally used by KMdiMainFrm to store a temporary information that the method
  165.      * activate() is unnecessary and that it can by escaped.
  166.      * This saves from unnecessary calls when activate is called directly.
  167.      */
  168.     bool m_bInterruptActivation;
  169.     
  170.     /**
  171.      * Internally used to prevent cycles between KMdiMainFrm::activateView() and KMdiChildView::activate().
  172.      */
  173.     bool m_bMainframesActivateViewIsPending;
  174.     
  175.     /**
  176.      * Internally used to check if there is a focus in event pending
  177.      */
  178.     bool m_bFocusInEventIsPending;
  179.  
  180.     // methods
  181. public:
  182.     /**
  183.      * Constructor
  184.      */
  185.     KMdiChildView( const QString& caption, QWidget* parentWidget = 0L, const char* name = 0L, WFlags f = 0 );
  186.     
  187.     /**
  188.      * Constructor 
  189.      * sets "Unnamed" as default caption
  190.      */
  191.     KMdiChildView( QWidget* parentWidget = 0L, const char* name = 0L, WFlags f = 0 );
  192.     
  193.     /**
  194.      * Destructor
  195.      */
  196.     ~KMdiChildView();
  197.     
  198.     /**
  199.      * This method does the same as focusInEvent(). That's why it is a replacement for the setFocus() call. It makes
  200.      * sense if you for instance want to focus (I mean raise and activate) this view although the real focus is
  201.      * in another toplevel widget. focusInEvent() will never get called in that case and your setFocus() call for this
  202.      * widget would fail without any effect.
  203.      * Use this method with caution, it always raises the view and pushes the taskbar button. Also when the focus is
  204.      * still on another MDI view in the same toplevel window where this is located!
  205.      */
  206.     void activate();
  207.     
  208.     /**
  209.      * Memorizes the first focusable child widget of this widget
  210.      */
  211.     void setFirstFocusableChildWidget( QWidget* );
  212.     
  213.     /**
  214.      * Memorizes the last focusable child widget of this widget
  215.      */
  216.     void setLastFocusableChildWidget( QWidget* );
  217.     
  218.     /**
  219.      * Returns the current focused child widget of this widget
  220.      */
  221.     QWidget* focusedChildWidget();
  222.     
  223.     /**
  224.      * Returns true if the MDI view is a child window within the MDI mainframe widget
  225.      * or false if the MDI view is in toplevel mode
  226.      */
  227.     bool isAttached() const { return ( mdiParent() != 0L ); }
  228.     
  229.     /**
  230.      * Returns the caption of the child window (different from the caption on the button in the taskbar)
  231.      */
  232.     const QString& caption() const { return m_szCaption; }
  233.     
  234.     /**
  235.      * Returns the caption of the button on the taskbar
  236.      */
  237.     const QString& tabCaption() const { return m_sTabCaption; }
  238.     
  239.     /**
  240.      * Sets the window caption string...
  241.      * Calls updateButton on the taskbar button if it has been set.
  242.      */
  243.     virtual void setCaption( const QString& szCaption );
  244.     
  245.     /**
  246.      * Sets the caption of the button referring to this window
  247.      */
  248.     virtual void setTabCaption( const QString& caption );
  249.     
  250.     /**
  251.      * Sets the caption of both the window and the button on the taskbar
  252.      */
  253.     virtual void setMDICaption( const QString &caption );
  254.     
  255.     /**
  256.      * Returns the KMdiChildFrm parent widget (or 0 if the window is not attached)
  257.      */
  258.     KMdiChildFrm *mdiParent() const;
  259.     
  260.     /**
  261.      * Tells if the window is minimized when attached to the Mdi manager,
  262.      * or if it is VISIBLE when 'floating'.
  263.      */
  264.     bool isMinimized() const;
  265.     
  266.     /**
  267.      * Tells if the window is minimized when attached to the Mdi manager,
  268.      * otherwise returns false.
  269.      */
  270.     bool isMaximized() const;
  271.     
  272.     /**
  273.      * Returns the geometry of this MDI child window as QWidget::geometry() does.
  274.      */
  275.     QRect internalGeometry() const;
  276.     
  277.     /**
  278.      * Sets the geometry of the client area of this MDI child window. The
  279.      * top left position of the argument is the position of the top left point
  280.      * of the client area in its parent coordinates and the arguments width
  281.      * and height is the width and height of the client area. Please note: This
  282.      * differs from the behavior of QWidget::setGeometry()!
  283.      */
  284.     void setInternalGeometry( const QRect& newGeomety );
  285.     
  286.     /**
  287.      * Returns the frame geometry of this window or of the parent if there is any...
  288.      */
  289.     QRect externalGeometry() const;
  290.     
  291.     /**
  292.      * Sets the geometry of the frame of this MDI child window. The top left
  293.      * position of the argument is the position of the top left point of the
  294.      * frame in its parent coordinates and the arguments width and height is
  295.      * the width and height of the widget frame. Please note: This differs
  296.      * from the behavior of QWidget::setGeometry()!
  297.      */
  298.     void setExternalGeometry( const QRect& newGeomety );
  299.     
  300.     /**
  301.      * You should override this function in the derived class.
  302.      */
  303.     virtual QPixmap* myIconPtr();
  304.     
  305.     /**
  306.      * Minimizes this window when it is attached to the Mdi manager.
  307.      * Otherwise has no effect
  308.      */
  309.     virtual void minimize( bool bAnimate );
  310.     
  311.     /**
  312.      * Maximizes this window when it is attached to the Mdi manager.
  313.      * Otherwise has no effect
  314.      */
  315.     virtual void maximize( bool bAnimate );
  316.     
  317.     /**
  318.      * Returns the geometry that will be restored by calling restore().
  319.      */
  320.     QRect restoreGeometry();
  321.     
  322.     /**
  323.      * Sets the geometry that will be restored by calling restore().
  324.      */
  325.     void setRestoreGeometry( const QRect& newRestGeo );
  326.     
  327.     /**
  328.      * Switches interposing in event loop of all current child widgets off.
  329.      */
  330.     void removeEventFilterForAllChildren();
  331.     
  332.     /**
  333.      * Internally used for setting an ID for the 'Window' menu entry
  334.      */
  335.     void setWindowMenuID( int id );
  336.     
  337.     /**
  338.      * Sets the minimum size of the widget to w by h pixels.
  339.      * It extends it base clase method in a way that the minimum size of
  340.      * its childframe (if there is one) will be set, additionally.
  341.      */
  342.     virtual void setMinimumSize ( int minw, int minh );
  343.     
  344.     /**
  345.      * Sets the maximum size of the widget to w by h pixels.
  346.      * It extends it base clase method in a way that the maximum size of
  347.      * its childframe (if there is one) will be set, additionally.
  348.      */
  349.     virtual void setMaximumSize ( int maxw, int maxh );
  350.     
  351.     /**
  352.      * Returns if this is added as MDI tool-view
  353.      */
  354.     inline bool isToolView() const { return m_bToolView; }
  355.     
  356.     /**
  357.      * Remember the current time
  358.      */
  359.     inline void updateTimeStamp()
  360.     {
  361.         m_time.setDate( QDate::currentDate() );
  362.         m_time.setTime( QTime::currentTime() );
  363.     }
  364.     
  365.     /**
  366.      * Recall a previously remembered time, i.e. the value of m_time
  367.      */
  368.     inline const QDateTime& getTimeStamp() const { return m_time; }
  369.  
  370. public slots:
  371.     /**
  372.     * Attaches this window to the Mdi manager.
  373.     * It calls the KMdiMainFrm attachWindow function , so if you have a pointer
  374.     * to this KMdiMainFrm you'll be faster calling that function.
  375.     */
  376.     virtual void attach();
  377.     
  378.     /**
  379.      * Detaches this window from the Mdi manager.
  380.      * It calls the KMdiMainFrm detachWindow function , so if you have a pointer
  381.      * to this KMdiMainFrm you'll be faster calling that function.
  382.      */
  383.     virtual void detach();
  384.     
  385.     /**
  386.      * Mimimizes the MDI view. If attached, the covering childframe widget is minimized (only a mini widget
  387.      * showing the caption bar and the system buttons will remain visible). If detached, it will use the
  388.      * minimize of the underlying system ( QWidget::showMinimized ).
  389.      */
  390.     virtual void minimize();
  391.     
  392.     /**
  393.      * Maximizes the MDI view. If attached, this widget will fill the whole MDI view area widget. The system buttons
  394.      * move to the main menubar (if set by KMdiMainFrm::setMenuForSDIModeSysButtons ).
  395.      * If detached, it will use the minimize of the underlying system ( QWidget::showMaximized ).
  396.      */
  397.     virtual void maximize();
  398.     
  399.     /**
  400.      * Restores this window to its normal size. Also known as 'normalize'.
  401.      */
  402.     virtual void restore();
  403.     
  404.     /**
  405.      * Internally called, if KMdiMainFrm::attach is called.
  406.      * Actually, only the caption of the covering childframe is set.
  407.      */
  408.     virtual void youAreAttached( KMdiChildFrm *lpC );
  409.     
  410.     /**
  411.      * Internally called, if KMdiMainFrm::detach is called.
  412.      * Some things for going toplevel will be done here.
  413.      */
  414.     virtual void youAreDetached();
  415.     
  416.     /**
  417.      * Called if someone click on the "Window" menu item for this child frame window
  418.      */
  419.     virtual void slot_clickedInWindowMenu();
  420.     
  421.     /**
  422.      * Called if someone click on the "Dock/Undock..." menu item for this child frame window
  423.      */
  424.     virtual void slot_clickedInDockMenu();
  425.     
  426.     /**
  427.      * Calls QWidget::show but also for it's parent widget if attached
  428.      */
  429.     virtual void show();
  430.     
  431.     /**
  432.      * Calls QWidget::hide() or it's parent widget hide() if attached
  433.      */
  434.     virtual void hide();
  435.     
  436.     /**
  437.      * Calls QWidget::raise() or it's parent widget raise() if attached
  438.      */
  439.     virtual void raise();
  440.     
  441.     /**
  442.      * Overridden from its base class method. Emits a signal KMdiChildView::isMinimizedNow , additionally.
  443.      * Note that this method is not used by an external windows manager call on system minimizing.
  444.      */
  445.     virtual void showMinimized();
  446.     
  447.     /**
  448.      * Overridden from its base class method. Emits a signal KMdiChildView::isMaximizedNow , additionally.
  449.      * Note that this method is not used by an external windows manager call on system maximizing.
  450.      */
  451.     virtual void showMaximized();
  452.     
  453.     /**
  454.      * Overridden from its base class method. Emits a signal KMdiChildView::isRestoredNow , additionally.
  455.      * Note that this method is not used by an external windows manager call on system normalizing.
  456.      */
  457.     virtual void showNormal();
  458.     
  459.  
  460. protected:
  461.     /**
  462.      * Ignores the event and calls KMdiMainFrm::childWindowCloseRequest instead. This is because the
  463.      * mainframe has control over the views. Therefore the MDI view has to request the mainframe for a close.
  464.      */
  465.     virtual void closeEvent( QCloseEvent *e );
  466.     
  467.     /**
  468.      * It only catches QEvent::KeyPress events there. If a Qt::Key_Tab is pressed, the internal MDI focus
  469.      * handling is called. That means if the last focusable child widget of this is called, it will jump to the
  470.      * first focusable child widget of this.
  471.      * See KMdiChildView::setFirstFocusableChildWidget and KMdiChildView::lastFirstFocusableChildWidget
  472.      */
  473.     virtual bool eventFilter( QObject *obj, QEvent *e );
  474.     
  475.     /**
  476.      * If attached, the childframe will be activated and the MDI taskbar button will be pressed. Additionally, the
  477.      * memorized old focused child widget of this is focused again.
  478.      * Sends the focusInEventOccurs signal before changing the focus and the
  479.      * gotFocus signal after changing the focus.
  480.      */
  481.     virtual void focusInEvent( QFocusEvent *e );
  482.     
  483.     /**
  484.      * Send the lostFocus signal
  485.      */
  486.     virtual void focusOutEvent( QFocusEvent *e );
  487.     
  488.     /**
  489.      * Internally used for the minimize/maximize/restore mechanism when in attach mode.
  490.      */
  491.     virtual void resizeEvent( QResizeEvent *e );
  492.  
  493.     void trackIconAndCaptionChanges( QWidget *view );
  494.  
  495. protected slots:
  496.     void slot_childDestroyed();
  497.  
  498. signals:
  499.     /**
  500.      * Internally used by KMdiChildView::attach to send it as command to the mainframe.
  501.      */
  502.     void attachWindow( KMdiChildView*, bool );
  503.     
  504.     /**
  505.      * Internally used by KMdiChildView::detach to send it as command to the mainframe.
  506.      */
  507.     void detachWindow( KMdiChildView*, bool );
  508.     
  509.     /**
  510.      * Is sent when this MDI child view is going to receive focus (before actually changing the focus).
  511.      * Internally used to send information to the mainframe that this MDI child view is focused.
  512.      * See KMdiChildView::focusInEvent
  513.      */
  514.     void focusInEventOccurs( KMdiChildView* );
  515.     
  516.     /**
  517.      * Is sent when this MDI child has received the focus (after actually changing the focus).
  518.      * See KMdiChildView::focusInEvent
  519.      */
  520.     void gotFocus( KMdiChildView* );
  521.     
  522.     /**
  523.      * Is sent when this MDI child was set to the activate view of all MDI views (after actually changing the focus).
  524.      * See KMdiChildView::activate
  525.      */
  526.     void activated( KMdiChildView* );
  527.     
  528.     /** Is sent when this MDI child view has lost the focus (after actually changing the focus).
  529.      *  See KMdiChildView::focusOutEvent
  530.      */
  531.     void lostFocus( KMdiChildView* );
  532.     
  533.     /** Is sent when this MDI child view was deactivated (after actually changing the focus).
  534.      *  See KMdiChildView::focusOutEvent
  535.      */
  536.     void deactivated( KMdiChildView* );
  537.     
  538.     /**
  539.      * Internally used to send information to the mainframe that this MDI child view wants to be closed.
  540.      * See KMdiChildView::closeEvent and KMdiMainFrm::closeWindow
  541.      */
  542.     void childWindowCloseRequest( KMdiChildView* );
  543.     
  544.     /**
  545.      * Emitted when the window caption is changed via KMdiChildView::setCaption or KMdiChildView::setMDICaption
  546.      */
  547.     void windowCaptionChanged( const QString& );
  548.     
  549.     /**
  550.      * Emitted  when the window caption is changed via KMdiChildView::setTabCaption or KMdiChildView::setMDICaption
  551.      */
  552.     void tabCaptionChanged( const QString& );
  553.     
  554.     /**
  555.      * Internally used to send information to the mainframe that this MDI view is maximized now.
  556.      * Usually, the mainframe switches system buttons.
  557.      */
  558.     void mdiParentNowMaximized( bool );
  559.     
  560.     /**
  561.      * Is automatically emitted when slot_clickedInWindowMenu is called
  562.      */
  563.     void clickedInWindowMenu( int );
  564.     
  565.     /**
  566.      * Is automatically emitted when slot_clickedInDockMenu is called
  567.      */
  568.     void clickedInDockMenu( int );
  569.     
  570.     /**
  571.      * Signals this has been maximized
  572.      */
  573.     void isMaximizedNow();
  574.     
  575.     /**
  576.      * Signals this has been minimized
  577.      */
  578.     void isMinimizedNow();
  579.     
  580.     /**
  581.      * Signals this has been restored (normalized)
  582.      */
  583.     void isRestoredNow();
  584.     
  585.     /**
  586.      * Signals this has been attached
  587.      */
  588.     void isAttachedNow();
  589.     
  590.     /**
  591.      * Signals this has been detached
  592.      */
  593.     void isDetachedNow();
  594.  
  595.     void iconUpdated( QWidget*, QPixmap );
  596.     void captionUpdated( QWidget*, const QString& );
  597.  
  598.  
  599. private:
  600.     KMdiChildViewPrivate *d;
  601.     QWidget *m_trackChanges;
  602. };
  603.  
  604. inline KMdiChildFrm *KMdiChildView::mdiParent() const
  605. {
  606.     QWidget * pw = parentWidget();
  607.     if ( pw != 0L )
  608.         if ( pw->inherits( "KMdiChildFrm" ) )
  609.             return ( KMdiChildFrm * ) pw;
  610.     return 0L;
  611. }
  612.  
  613. #endif //_KMDICHILDVIEW_H_
  614.  
  615. // kate: space-indent off; replace-tabs off; indent-mode csands; tab-width 4;
  616.